package com.cbg.controller;

import com.cbg.pojo.TbItem;
import com.cbg.service.ItemService;
import org.apache.commons.net.ftp.FTPClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;

/**
 * Created by chenboge on 2017/8/20.
 * <p>
 * Email:baigegechen@gmail.com
 * <p>
 * description:
 */
@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    @ResponseBody
    @RequestMapping("/item/{itemId}")
    public TbItem getTbItemById(@PathVariable long itemId) {
        return itemService.getTbItemById(itemId);
    }

    @RequestMapping("/file")
    public void test() {
        FTPClient client = new FTPClient();
        try {
            client.connect("localhost", 21);
            client.login("daemon", "xampp");
            FileInputStream inputStream = new FileInputStream(new File("/Volumes/soft/相册/201508信安比赛/IMG_1375.JPG"));
            client.changeWorkingDirectory("/img");
            client.storeFile("hello.jpg", inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
